package com.party.tool;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
/**
 * 
 * @author Caizhf
 * @date 2017年7月24日上午12:34:02
 * @version v.0.1
 * @email 1115054416@qq.com 
 *
 * <p>Description: 由于当前服务器非集群分布式，并发也较小，此方案目前已经能够满足需求</p>
 *
 */
public class OrdersNumUtils {
	
	
	private final static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
	
	
	//根据时间生成订单，组合： 时间串+5位随机数 +5位随机数
	public static String getOrdersNum(){
		Random rd = new Random();
		int max = 99999;
		int min = 10000;
		String time = sdf.format(new Date(System.currentTimeMillis()));
		int randomNumStart = rd.nextInt(max)%(max-min+1) + min;
		int randomNumEnd = rd.nextInt(max)%(max-min+1) + min;
		return "" + time + randomNumStart + randomNumEnd;
	}
	
	//判断是否周末
	public static boolean isWeekend(Calendar cal){  
	    int week=cal.get(Calendar.DAY_OF_WEEK)-1;  
	    if(week ==6 || week==0){//0代表周日，6代表周六  
	        return true;  
	    }  
	    return false;  
	}  
	
	public static String getRefundNum(){
		Random rd = new Random();
		String time = sdf.format(new Date(System.currentTimeMillis()));
		int max = 99999;
		int min = 10000;
		int randomNumEnd = rd.nextInt(max)%(max-min+1) + min;
		return "" + time + randomNumEnd;
	}
}
